package com.wmeimob.fastboot.jiubei.config;

import com.wmeimob.fastboot.jiubei.entity.Member;
import com.wmeimob.fastboot.starter.security.interfaces.JsonWebTokenDecoder;
import io.jsonwebtoken.Claims;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author Meimeng
 */
public class UserInfoJsonWebTokenDecoder implements JsonWebTokenDecoder {


    @Override
    public UserDetails decode(Claims claims) {

        Integer id = (Integer) claims.get("id");
        String phone = (String) claims.get("phone");
        String nickname = (String) claims.get("nickname");
        String headImg = (String) claims.get("headImg");
        String vipNo = (String) claims.get("vipNo");

        //返回给spring security
        Member member = new Member();
        member.setId(Long.valueOf(id));
        member.setNickname(nickname);
        member.setVipNo(vipNo);
        member.setHeadImg(headImg);
        member.setPhone(phone);
        return member;
    }

}
